﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Coolite.Ext.Web;
using CXDB;
using SubSonic;
using Coolite.Ext;

public partial class Safty_UserList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       CXSecurity.ChkDept("6"); 
    }
    protected void RowSelect(object sender, AjaxEventArgs e)
    {
        string uID = e.ExtraParams["uID"];
        TfUserID.Value = uID;
        Query q = new Query(VwUserBase.Schema);
        q.SetSelectList("username,depid,deptname");
        q.AddWhere("uID", uID);
        IDataReader dr = q.ExecuteReader();
        if (dr.Read())
        {
            Tfusername.Text = dr[0].ToString();
            TfDeptID.Value = dr[1].ToString();
            TfDeptName.Text = dr[2].ToString();
            //FormPanel1.Title = "员工诚信档案记录表:" + dr[0].ToString();
            
        }

    }
    [AjaxMethod]
    protected void SubReportAdd(object sender, AjaxEventArgs e)
    {
        if (TfUserID.Value.ToString() == "")
        {
            Err.Warning("请在左侧列表选择一个员工！", MessageBox.Icon.WARNING);
        }
        else
        {
            if (Cookies.getCookies("cDeptID") != "6")
            {
                Err.Warning("对不起，您没有权限进行此项操作！", MessageBox.Icon.ERROR);
            }
            else
            {
                if (TfSafty_MasterId.SelectedIndex == -1)
                {
                    Err.Warning("请选择安监部领导！", MessageBox.Icon.WARNING);
                }
                else
                {
                    //添加表单
                    Guid g = Guid.NewGuid();
                    CxStaffSafty cx = new CxStaffSafty();
                    cx.UserID = int.Parse(TfUserID.Value.ToString());
                    cx.DeptID = int.Parse(TfDeptID.Text);
                    cx.AccidentTime = DateTime.Parse(TfAccident_time.Value.ToString());
                    cx.AccidentDuty = TfAccident_duty.SelectedItem.Value;
                    cx.AccidentReason = TfAccident_reason.Text;
                    cx.SaftyMasterID = int.Parse(TfSafty_MasterId.SelectedItem.Value);
                    cx.SaftyMasterStatus = 0;
                    //cx.DeptMasterStatus = 0;
                    cx.EnteringUserID = int.Parse(Cookies.getCookies("cUID"));
                    cx.Status = 0;
                    cx.Guid = g;
                    cx.Save();
                    CXFileUpload.Sv(tffileupload, g);

                    //清空表单
                    //FormPanel1.Title = "员工诚信档案记录表";
                    TfDeptName.Text = "";
                    TfUserID.Value = "";
                    TfDeptID.Value = "";
                    TfAccident_time.Value = "";
                    TfAccident_reason.Text = "";
                    TfAccident_duty.Value = "";
                    Tfusername.Text = "";
                    TfSafty_MasterId.Reset();


                    Err.Warning("已提交，请等待该员工部门主管回复及总经理审批！",MessageBox.Icon.NONE);

                }
            }
        }
    }
}
